/**
 * Created by larry.quns on 2022/1/8.
 */

function antForestGo() {
    toast("初始化");
    utils.openApp("com.eg.android.AlipayGphone");//打开阿里app
    sleep(random(500, 1200));
    antForestGoZFBHome()
    if (findNode(id("com.alipay.android.phone.openplatform:id/app_text").textMatch(textMatchPlus("蚂蚁森林")), true)) {
        sleep(random(150,350));
    } else {
        toast("未找到蚂蚁森林！");
        loge("未找到蚂蚁森林！");
    }
    toast("蚂蚁森林开始自动获取能量");
    startEnergyBall();//蚂蚁森林
}

let antForestGoHomeCount = 0;

function antForestGoZFBHome() {
    if (findNode(id("com.alipay.android.phone.openplatform:id/tab_description").text("首页"), true)) {
        sleep(random(150,350));
        logd("找到支付宝首页");
        return true;
    }
    antForestGoHomeCount = antForestGoHomeCount + 1;
    if (antForestGoHomeCount >= 10) {
        loge("未找到支付宝首页！");
        return false;
    }
    loge("点击返回按钮");
    back();
    sleep(random(800, 1500))
    antForestGoZFBHome();
}